﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _13_RomanNumeralsEncoder
{
	public class RomanConvert
	{
		//罗马字符对应关系
		//字符		数值
		//I             1
		//V             5
		//X             10
		//L             50
		//C             100
		//D             500
		//M             1000
		/// <summary>
		/// 罗马字符
		/// </summary> 
		public static string Solution(int n)
		{
            Dictionary<int, string> dicNums = new Dictionary<int, string>()
            {
                {1000,"M" },
                {900,"CM" },
                {500,"D" },
                {400,"CD" },
                {100,"C" },
                {90,"XC" },
                {50,"L" },
                {40,"XL" },
                {10,"X" },
                {9,"IX" },
                {5,"V" },
                {4,"IV" },
                {1,"I"}
            };
            StringBuilder sb = new StringBuilder();            
            while (n > 0)
            {
                foreach (var item in dicNums.Keys)
                {
                    if (n - item >= 0)
                    {
                        sb.Append(dicNums[item]);
                        n -= item;
                        break;
                    }
                    else
                        continue;
                }
            }
            return sb.ToString();
		}
	}
}
